﻿@{
    ViewBag.Title = "MembersIndex";
    Layout = "~/Views/Shared/_Index.cshtml";
}
<script>
    $(function () {
        gridList();
    })
    function gridList() {
        function getsearchData() {
            var searchData = {
                F_Account: $("#txt_F_Account").val(),
                F_RealName: $("#txt_F_RealName").val()
                //,
                //CurrentManagerType: $('#sel_ManagerType').val(),
                //GroupStatus: $("#sel_GroupStatus").val()
            };
            var pd = { pData: JSON.stringify(searchData) };
            return pd;
        }


        var $gridList = $("#gridList");
        $gridList.dataGrid({
            url: "/SystemManage/User/GetMembersGridJson",
            height: $(window).height() - 128,
            colModel: [
                { label: '主键', name: 'F_Id', hidden: true },
                { label: '会员ID', name: 'F_Account', width: 140, align: 'left' },
                { label: '会员姓名', name: 'F_RealName', width: 80, align: 'left' },
                { label: '身份证号', name: 'F_CardId', width: 140, align: 'left' },
                { label: '联系方式', name: 'F_MobilePhone', width: 80, align: 'left' },
                { label: '账户余额', name: 'F_MemberMoney', width: 80, align: 'left' },
                { label: '推荐人ID', name: 'ReferenceAccount', width: 80, align: 'left' },
                { label: '推荐人姓名', name: 'ReferenceName', width: 80, align: 'left' },
                { label: '收货地址', name: 'F_Address', width: 80, align: 'left' },
                {
                    label: '创建时间', name: 'F_CreatorTime', width: 130, align: 'left',
                    formatter: "date", formatoptions: { srcformat: 'Y-m-d H:i:s', newformat: 'Y-m-d H:i:s' }
                },
                {
                    label: "允许登录", name: "F_EnabledMark", width: 60, align: "center",
                    formatter: function (cellvalue, options, rowObject) {
                        if (cellvalue == 1) {
                            return '<span class=\"label label-success\">正常</span>';
                        } else if (cellvalue == 0) {
                            return '<span class=\"label label-default\">禁用</span>';
                        }
                    }
                }
            ],
            pager: "#gridPager",
            sortname: 'F_CreatorTime',
            viewrecords: true,
            postData: getsearchData(),
            footerrow: true,
            gridComplete: completeMethod
        });
        $("#btn_search").click(function () {
            $gridList.jqGrid('setGridParam', {
                postData: getsearchData()
            }).trigger('reloadGrid');
        });
    }
    function completeMethod() {
        $.ajax({
            url: "/SystemManage/User/GetAllMemberAccount?keyAccount=" + $("#txt_F_Account").val() + "&keyRealName=" + $("#txt_F_RealName").val() + "",
            success: function (result) {
                $("#gridList").footerData('set', { F_Account: '余额合计:' + result.SumAmount});
            }
        });
    }

    function btn_add() {
        $.modalOpen({
            id: "Form",
            title: "新增会员",
            url: "/SystemManage/User/MembersForm",
            width: "700px",
            height: "620px",
            btn: null,
            callBack: function (iframeId) {
                top.frames[iframeId].submitForm();
            }
        });
    }
    function btn_edit() {
        var keyValue = $("#gridList").jqGridRowValue().F_Id;
        $.modalOpen({
            id: "Form",
            title: "会员充值",
            url: "/SystemManage/User/MemberRecharge?keyValue=" + keyValue,
            width: "700px",
            height: "300px",
            callBack: function (iframeId) {
                top.frames[iframeId].submitForm();
            }
        });
    }
    function btn_delete() {
        var keyValue = $("#gridList").jqGridRowValue().F_Id;
        $.modalOpen({
            id: "Form",
            title: "会员扣费",
            url: "/SystemManage/User/MemberFRecharge?keyValue=" + keyValue,
            width: "700px",
            height: "300px",
            callBack: function (iframeId) {
                top.frames[iframeId].submitForm();
            }
        });
    }
    function btn_details() {
        var keyValue = $("#gridList").jqGridRowValue().F_Id;
        $.modalOpen({
            id: "Details",
            title: "会员详情",
            url: "/SystemManage/User/MembersInfo?keyValue=" + keyValue,
            width: "700px",
            height: "620px",
            btn: null,
        });
    }
    function btn_revisepassword() {
        var keyValue = $("#gridList").jqGridRowValue().F_Id;
        var Account = $("#gridList").jqGridRowValue().F_Account;
        var RealName = $("#gridList").jqGridRowValue().F_RealName;
        $.modalOpen({
            id: "RevisePassword",
            title: '重置密码',
            url: '/SystemManage/User/RevisePassword?keyValue=' + keyValue + "&account=" + escape(Account) + '&realName=' + escape(RealName),
            width: "450px",
            height: "260px",
            callBack: function (iframeId) {
                top.frames[iframeId].submitForm();
            }
        });
    }
    function btn_disabled() {
        var keyValue = $("#gridList").jqGridRowValue().F_Id;
        $.modalConfirm("注：您确定要【禁用】该项账户吗？", function (r) {
            if (r) {
                $.submitForm({
                    url: "/SystemManage/User/DisabledAccount",
                    param: { keyValue: keyValue },
                    success: function () {
                        $.currentWindow().$("#gridList").trigger("reloadGrid");
                    }
                })
            }
        });
    }
    function btn_enabled() {
        var keyValue = $("#gridList").jqGridRowValue().F_Id;
        $.modalConfirm("注：您确定要【启用】该项账户吗？", function (r) {
            if (r) {
                $.submitForm({
                    url: "/SystemManage/User/EnabledAccount",
                    param: { keyValue: keyValue },
                    success: function () {
                        $.currentWindow().$("#gridList").trigger("reloadGrid");
                    }
                })
            }
        });
    }
</script>

<div class="topPanel">
    <div class="toolbar">
        @*<div class="btn-group">
            <a class="btn btn-primary" onclick="$.reload()"><span class="glyphicon glyphicon-refresh"></span></a>
        </div>*@
        <div class="btn-group">
            <a id="NF-add" authorize="yes" class="btn btn-primary dropdown-text" onclick="btn_add()"><i class="fa fa-plus"></i>新建会员</a>
        </div>
        <div class="operate">
            <ul class="nav nav-pills">
                <li class="first">已选中<span>1</span>项</li>
                <li><a id="NF-edit" authorize="yes" onclick="btn_edit()"><i class="fa fa-pencil-square-o"></i>会员充值</a></li>
                <li><a id="NF-delete" authorize="yes" onclick="btn_delete()"><i class="fa fa-trash-o"></i>会员扣费</a></li>
                <li><a id="NF-Details" authorize="yes" onclick="btn_details()"><i class="fa fa-search-plus"></i>会员详情</a></li>
                <li class="split"></li>
                <li><a id="NF-revisepassword" authorize="yes" onclick="btn_revisepassword()"><i class="fa fa-key"></i>密码重置</a></li>
                <li class="split"></li>
                <li><a id="NF-disabled" authorize="yes" onclick="btn_disabled()"><i class="fa fa-stop-circle"></i>禁用</a></li>
                <li><a id="NF-enabled" authorize="yes" onclick="btn_enabled()"><i class="fa fa-play-circle"></i>启用</a></li>
            </ul>
            <a href="javascript:;" class="close"></a>
        </div>
        <script>$('.toolbar').authorizeButton()</script>
    </div>
    <div class="search">
        <table>
            <tr>
                <td>
                    <div class="input-group">
                        <input id="txt_F_Account" type="text" class="form-control" placeholder="会员ID" style="width: 100px;">
                        <input id="txt_F_RealName" type="text" class="form-control" placeholder="会员姓名" style="width: 100px;">
                        @*<select id="sel_ManagerType" class="form-control" placeholder="选择级别" style="width: 100px;" >
                            <option value="-1" selected="selected" >全部</option>
                            <option value="0" >普通身份</option>
                            <option value="3">黄金董事</option>
                            <option value="4">红宝石董事</option>
                            <option value="5">翡翠董事</option>
                            <option value="6">钻石董事</option>
                            <option value="7">荣誉董事</option>
                        </select>
                        <select id="sel_GroupStatus" class="form-control" placeholder="选择级别" style="width: 100px;">
                            <option value="-1" selected="selected" >全部</option>
                            <option value="0">经理</option>
                            <option value="1">副经理</option>
                            <option value="2">组员</option>
                            <option value="3">新组员</option>
                        </select>*@
                        <span class="input-group-btn">
                            <button id="btn_search" type="button" class="btn  btn-primary"><i class="fa fa-search"></i></button>
                        </span>
                    </div>
                </td>
            </tr>
        </table>
    </div>
</div>
<div class="gridPanel">
    <table id="gridList"></table>
    <div id="gridPager"></div>
</div>
